package com.util.check;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description 特殊字符校验
 * @Author zhu_jinsheng[zhu_js@suixingpay.com]
 * @Date 2019/12/5 9:51
 * @Version 1.0
 */
public class CharacterCheck {
    /**
     * 校验字符串是否只包含汉字、英文、数字
     * @param str
     * @return
     */
    public static boolean specialCharacter(String str){
        String regex="^[a-zA-Z0-9\u4E00-\u9FA5]+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher match=pattern.matcher(str);
        return match.matches();
    }

    /**
     * 将字符串中汉字、英文、数字以外的字符替换成空格
     * @param str
     * @return
     */
    public static String specialCharacterReplace(String str){
        String regex="[^a-zA-Z0-9\u4E00-\u9FA5]";
        return str.replaceAll(regex, " ");
    }
}
